var MailLab = Class.create();
MailLab.prototype = {
	initialize: function() {
                        this.star_list = false;
                        this.d_inbox = false;
                    },
        initEvent: function(){
                       var self = this;
                       Event.observe(DOM.mailConfiguration, 'click', function(event) {
			var EL = $(event.target);
                        try{
                        var e = Element.getParentNodeByClassName(EL, 's_cfg_lab_com');
                            if (e) {
                                mailLab.saveCfg();
                            }
                        }catch(e){
                        }
                        });
                   },
        loadConfigPanel: function(){
                             if(USE_SYS.domain == "vip"){
                                var data = new Array;
                                var URLS = {
                                    vip : 'vipmail',
                                    sogou : 'sogoumail',
                                    chinaren : 'chinarenmail',
                                    sohu : 'sohumail'
                                };
                                data['DOWNLOADLINK'] = MailConst.ALL + "/links/" + URLS[USE_SYS.domain] + ".url";
                                data["STAR_LIST"] = '<input id="star_list" name="star_list" type="radio" value="true" class="s_lab" />开启<input  id="star_list" name="star_list" type="radio" value="false" checked="checked" class="s_lab" /> 关闭';
                                data['D_INBOX'] = '<input name="d_inbox" id="d_inbox" type="radio" value="true" class="s_lab" />开启<input name="d_inbox" id="d_inbox" type="radio" value="false"  checked="checked"  class="s_lab"/>关闭';
                                if(PROFILE.star_list == true || PROFILE.star_list == "true"){
                                    data["STAR_LIST"] = '<input id="star_list" checked="checked" name="star_list" type="radio" value="true" class="s_lab" />开启<input  id="star_list" name="star_list" type="radio" value="false" class="s_lab" /> 关闭';
                                }
                                if(PROFILE.d_inbox == true || PROFILE.d_inbox == "true"){
                                    data['D_INBOX'] = '<input name="d_inbox" id="d_inbox" type="radio" value="true" checked="checked" class="s_lab" />开启<input name="d_inbox" id="d_inbox" type="radio" value="false"  class="s_lab"/>关闭';
                                }
			        var t = new Template(VIPLabTemplete);
                                DOM.mailConfiguration.innerHTML = t.evaluate(data);
		                hiddenAllPanel();
                                DOM.mailConfiguration.show();
                             }else{
                                 _defun('http://mail.' + USE_SYS.domain + '.com/mapp/interfaces/dream.jsp?' + Math.round(Math.random()*10000), 'get', {}, this.loadConfigPanelCallBack.bind(this));
                             }
                  },
        loadConfigPanelCallBack: function(ret){
		hiddenAllPanel();
		DOM.mailConfiguration.show();
                        var data = new Array;
                        var URLS = {
vip : 'vipmail',
      sogou : 'sogoumail',
      chinaren : 'chinarenmail',
      sohu : 'sohumail'
                        };
                        data['DOWNLOADLINK'] = MailConst.ALL + "/links/" + URLS[USE_SYS.domain] + ".url";
                        data['DREG'] = MailConst.ALL + "/links/sohumail_help.reg";
                        data["STAR_LIST"] = '<input id="star_list" name="star_list" type="radio" value="true" class="s_lab" />开启<input  id="star_list" name="star_list" type="radio" value="false" checked="checked" class="s_lab" /> 关闭';
                        data['D_INBOX'] = '<input name="d_inbox" id="d_inbox" type="radio" value="true" class="s_lab" />开启<input name="d_inbox" id="d_inbox" type="radio" value="false"  checked="checked"  class="s_lab"/>关闭';
                        if(PROFILE.star_list == true || PROFILE.star_list == "true"){
                            data["STAR_LIST"] = '<input id="star_list" checked="checked" name="star_list" type="radio" value="true" class="s_lab" />开启<input  id="star_list" name="star_list" type="radio" value="false" class="s_lab" /> 关闭';
                        }
                        if(PROFILE.d_inbox == true || PROFILE.d_inbox == "true"){
                            data['D_INBOX'] = '<input name="d_inbox" id="d_inbox" type="radio" value="true" checked="checked" class="s_lab" />开启<input name="d_inbox" id="d_inbox" type="radio" value="false"  class="s_lab"/>关闭';
                        }
                        var r = null;
                        try{
                           r = ret.strip().evalJSON();
                           r = r.evalJSON();
                        }
                        catch(e){
                            // 如果出错,干脆走VIP的样子
			    var t = new Template(VIPLabTemplete);
			    DOM.mailConfiguration.innerHTML = t.evaluate(data);
                        }
                                     
                        var img_src = '';
                        for(var i = 0; i < r.dream1; i++){
                            img_src += '<img  align="absmiddle" src="' + MailConst.ALL + '/star1.gif" />';
                        }
                        for(var i = 0; i < 4 - r.dream1; i++){
                            img_src += '<img align="absmiddle"  src="' + MailConst.ALL + '/star2.gif" />';
                        }
                        data['DREAM_1'] = img_src;
                        img_src = '';
                        for(var i = 0; i < r.dream2; i++){
                            img_src += '<img align="absmiddle" src="' + MailConst.ALL + '/star1.gif" />';
                        }
                        for(var i = 0; i < 4 - r.dream2; i++){
                            img_src += '<img  align="absmiddle" src="' + MailConst.ALL + '/star2.gif" />';
                        }
                        data['DREAM_2'] = img_src;
                        img_src = '';
                        for(var i = 0; i < r.dream3; i++){
                            img_src += '<img  align="absmiddle" src="' + MailConst.ALL + '/star1.gif" />';
                        }
                        for(var i = 0; i < 4 - r.dream3; i++){
                            img_src += '<img  align="absmiddle" src="' + MailConst.ALL + '/star2.gif" />';
                        }
                        data['DREAM_3'] = img_src;

			var t = new Template(LabTemplete);
			DOM.mailConfiguration.innerHTML = t.evaluate(data);
                 },
        saveCfg: function(key, value){
		    var cf = $('labdiv');
                    var s_list = mailCfgClass.getRadioCheckedValue(cf.star_list);
                    var d_in = mailCfgClass.getRadioCheckedValue(cf.d_inbox);
                    var params = {
                        d_inbox : d_in,
                        star_list: s_list
                    }
                    try{
                        if(d_in != PROFILE.d_inbox){
                            d_in == false ? jsoplog.ucCapture('d_in_false') : jsoplog.ucCapture('d_in_true');
                        }
                    }catch(e){}
                    try{
                        if(s_list != PROFILE.star_list){
                            s_list == false ? jsoplog.ucCapture('starlist_false') : jsoplog.ucCapture('starlist_true');
                        }
                    }catch(e){}
                    PROFILE.d_inbox = d_in;
                    PROFILE.star_list = s_list;
                    mailStarList.rebuild();
                    profile_set(params, this.setMailCfgCallBack.bind(this));
                 },
                setMailCfgCallBack:function(ret){
                    if (ret.is_success) {
                        mailStarList.rebuild();
		        mailCfgClass.cfgSuccPrompt = true;
			mailCfgClass.initMailCfg();
                    }
                                   }
};


var mailLab = new MailLab();
